package threads;

import java.util.Stack;

public class Consumer extends MyThread implements MyThreadsOperations {

	public Consumer(String name, Stack<Integer> mBox, long cycle) {
		super(name);
		setThreadOperations(this);
		localMBox = mBox;
		cycleLength_msec = cycle;
	}

//	public void run(){
//		boolean running = true;
//		while(running){
//			try {
//				sleep(cycleLength_msec);
//				//localMBox.wait();
//				consume();
//			} catch (InterruptedException e) {
////				e.printStackTrace();
//				running = false;
//				System.out.println(getName()+ "I'm interrupted");
//			}
//		}
//		localMBox.notify();
//	}
	
	public void consume(){
		if(!localMBox.isEmpty()){
			Integer cons;
			cons = localMBox.pop();
			System.out.println(getName() +" consumed "+cons.intValue());
		}else{
			System.out.println(getName()+ " nothing");
		}
		
	}

@Override
public void threadOperations() throws InterruptedException {
	while(!localMBox.empty())
		consume();
}
	
}
